package com.fmjava.service_video.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fmjava.service_video.entity.Content;
import com.fmjava.service_video.entity.vo.ContentPreviewVo;
import com.fmjava.service_video.entity.vo.ContentVo;
import com.fmjava.service_video.service.ContentService;
import com.fmjava.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 作品表 前端控制器
 * </p>
 *
 * @author fmjava
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/service_video/content")
@Api(tags = "商品基本信息组")
public class ContentController {
    @Autowired
    ContentService contentService;

    @ApiOperation(value = "添加商品基本信息,并返回主键给前端")
    @PostMapping("/addContentInfo")
    public ResponseResult insertContent(@ApiParam(name = "contentVo",value = "商品基本信息",required = true) @RequestBody ContentVo contentVo){
        //1、添加作品基本信息

        //2、添加作品描述
       String id= contentService.insertContent(contentVo);
        return ResponseResult.ok().data("id",id);
    }

    @ApiOperation(value = "根据id获取content")
    @GetMapping("/getOneContent/{id}")
    public ResponseResult getOneContent(@ApiParam(name = "id",value = "获取content需要的id",required = true)@PathVariable String id){
        ContentVo contentVo=contentService.getOneContent(id);
        return ResponseResult.ok().data("contentVo",contentVo);
    }

    @ApiOperation(value = "修改 content")
    @PostMapping("/updateContent")
    public ResponseResult updateContent(@ApiParam(name = "contentVo", value = "修改content",required = true)@RequestBody ContentVo contentVo){
        contentService.updateContent(contentVo);
      return   ResponseResult.ok();
    }

    @ApiOperation(value = "获取作品模型")
    @GetMapping("/getContentView/{id}")
    public ResponseResult getContentView(@ApiParam(name = "id",value = "查询作品模型参数",required = true)@PathVariable String id)
    {
       ContentPreviewVo contentPreviewVo= contentService.getContentView(id);
        return ResponseResult.ok().data("view",contentPreviewVo);
    }

    @ApiOperation(value = "发布作品")
    @PostMapping("sendContent/{id}")
    public ResponseResult sendContent(@ApiParam(name = "id",value = "发布作品的作品id",required = true)@PathVariable String id){
        Content content = new Content();
        content.setId(id);
        content.setStatus("Normal");
        contentService.updateById(content);
        return ResponseResult.ok();
    }
    @GetMapping("/getContentPageQuery/{page}/{limit}")
    public ResponseResult getContentList(@PathVariable Long page,@PathVariable Long limit, ContentVo contentVo){
        System.out.println(contentVo);
        Page<Content> pageContent = new Page<>(page, limit);
        contentService.getContentList(pageContent,contentVo);
        List<Content> records = pageContent.getRecords();
        long total = pageContent.getTotal();
        return ResponseResult.ok().data("contentList",records).data("total",total);
    }

    @PostMapping("/deleteContent/{id}")
    public  ResponseResult deleteContent(@PathVariable String id){
        contentService.deleteContent(id);
        return  ResponseResult.ok();
    }
}

